package com.alone.openai.api.core;

import com.alone.openai.api.core.param.*;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;

/**
 * @author Alone
 * @date 2023/3/22 10:10 上午
 */
public final class Api {

    /**
     * Lists the currently available models, and provides basic information about each one such as the owner and availability.
     * <p>
     * 列出当前可用的模型，并提供有关每个模型的基本信息，例如所有者和可用性。
     */
    public static final ApiDefinition<Void, ModelList> LIST_MODEL_V1 = ApiDefinition.builder(Void.class, ModelList.class)
            .method(HttpMethod.GET)
            .url(ApiConstant.URL_GET_LIST_MODEL_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .enableLog()
            .build();

    /**
     * Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
     * <p>
     * 检索模型实例，提供有关模型的基本信息，例如所有者和许可。
     */
    public static final ApiDefinition<String, ModelItem> RETRIEVE_MODEL_V1 = ApiDefinition.builder(String.class, ModelItem.class)
            .method(HttpMethod.GET)
            .url(ApiConstant.URL_GET_RETRIEVE_MODEL_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .path("model", in -> in)
            .enableLog()
            .build();


    /**
     * Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
     * <p>
     * 给定提示，模型将返回一个或多个预测结果，并且还可以返回每个位置的替代令牌的概率。
     */
    public static final ApiDefinition<CompletionParam, CompletionResponse> COMPLETIONS_V1 = ApiDefinition.builder(CompletionParam.class, CompletionResponse.class)
            .method(HttpMethod.POST)
            .url(ApiConstant.URL_POST_CREATE_COMPLETIONS_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .body(in -> in)
            .enableLog()
            .build();

    /**
     * Given a chat conversation, the model will return a chat completion response.
     * <p>
     * 给定聊天对话，模型将返回回复结果。
     */
    public static final ApiDefinition<ChatParam, ChatResponse> CHAT_V1 = ApiDefinition.builder(ChatParam.class, ChatResponse.class)
            .method(HttpMethod.POST)
            .url(ApiConstant.URL_POST_CREATE_CHAT_COMPLETIONS_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .body(in -> in)
            .enableLog()
            .build();

    /**
     * Given a prompt and an instruction, the model will return an edited version of the prompt.
     * <p>
     * 给定提示和指令，模型将返回提示的编辑版本。
     */
    public static final ApiDefinition<EditParam, EditResponse> EDIT_V1 = ApiDefinition.builder(EditParam.class, EditResponse.class)
            .method(HttpMethod.POST)
            .url(ApiConstant.URL_POST_CREATE_EDIT_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .body(in -> in)
            .enableLog()
            .build();

    /**
     * Creates an image given a prompt.
     * <p>
     * 给定提示创建图像。
     */
    public static final ApiDefinition<ImageGenerationParam, ImageGenerationResponse> IMG_V1 = ApiDefinition.builder(ImageGenerationParam.class, ImageGenerationResponse.class)
            .method(HttpMethod.POST)
            .url(ApiConstant.URL_POST_CREATE_IMAGE_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .body(in -> in)
            .enableLog()
            .build();

    /**
     * Creates an edited or extended image given an original image and a prompt.
     * <p>
     * 给定原始图像和提示，创建已编辑或扩展的图像。
     */
    public static final ApiDefinition<ImageEditParam, ImageGenerationResponse> IMG_EDIT_V1 = ApiDefinition.builder(ImageEditParam.class, ImageGenerationResponse.class)
            .method(HttpMethod.POST)
            .url(ApiConstant.URL_POST_CREATE_IMAGE_EDIT_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .body(in -> in)
            .enableLog()
            .build();


    /**
     * Creates a variation of a given image.
     * <p>
     * 创建给定图像的变体。
     */
    public static final ApiDefinition<ImageVariationParam, ImageVariationResponse> IMG_VARIATION_V1 = ApiDefinition.builder(ImageVariationParam.class, ImageVariationResponse.class)
            .method(HttpMethod.POST)
            .url(ApiConstant.URL_POST_CREATE_IMAGE_VARIATION_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .body(in -> in)
            .enableLog()
            .build();

    /**
     * Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
     * <p>
     * 获取给定输入的向量表示，该向量表示可以很容易地被机器学习模型和算法消耗。
     */
    public static final ApiDefinition<EmbeddingParam, EmbeddingResponse> EMBEDDING_V1 = ApiDefinition.builder(EmbeddingParam.class, EmbeddingResponse.class)
            .method(HttpMethod.POST)
            .url(ApiConstant.URL_POST_CREATE_EMBEDDINGS_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .body(in -> in)
            .enableLog()
            .build();

    /**
     * Translates audio into into English.
     * <p>
     * 将音频翻译成英语。
     */
    public static final ApiDefinition<AudioTranslationParam, AudioTranslationResponse> AUDIO_TRANSLATION_V1 = ApiDefinition.builder(AudioTranslationParam.class, AudioTranslationResponse.class)
            .method(HttpMethod.POST)
            .url(ApiConstant.URL_POST_CREATE_TRANSLATION_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .body(in -> in)
            .enableLog()
            .build();

    /**
     * Transcribes audio into the input language.
     * <p>
     * 将音频转录成输入语言。
     */
    public static final ApiDefinition<AudioTranscriptionParam, AudioTranscriptionResponse> AUDIO_TRANSCRIPTION_V1 = ApiDefinition.builder(AudioTranscriptionParam.class, AudioTranscriptionResponse.class)
            .method(HttpMethod.POST)
            .url(ApiConstant.URL_POST_CREATE_TRANSCRIPTION_V1)
            .header(HttpHeaders.AUTHORIZATION, in -> GlobalProperties.getToken())
            .header(HttpHeaders.CONTENT_TYPE, ApiConstant.CONTENT_TYPE)
            .body(in -> in)
            .enableLog()
            .build();

}
